from app.core.img_opencv import *
from app.core.key_board import *
from app.work.work_public import *

# region 神秘商人
def Mysterious_Merchant_work(buy_index,scale,key_map):
    """
    神秘商人过程
    """
    find_NPC_way("神秘商人",scale,key_map)
    wait_click_image('app_img/Mysterious_Merchant/4_1.png', threshold=0.7, scale=scale)
    wait_image('app_img/Mysterious_Merchant/4_2.png', threshold=0.7, scale=scale)
    while True:
        if(buy_index==1):
            click_image('app_img/Mysterious_Merchant/5_1.png',image_num=2, threshold=0.7, scale=scale)
        elif(buy_index==2):
            click_image('app_img/Mysterious_Merchant/5_1.png', threshold=0.7, scale=scale)
        elif(buy_index==3):
            click_image('app_img/Mysterious_Merchant/5_1.png', threshold=0.7, scale=scale)
            if_exist_click_image('app_img/public_img/yes.png', threshold=0.7, scale=scale)
            break
        if_exist_click_image('app_img/public_img/yes.png', threshold=0.7, scale=scale)
        if(is_image_now('app_img/Mysterious_Merchant/6_1.png', threshold=0.7, scale=scale)):
            break

# region 宝库
def baoku_work(scale):
    """
    宝库过程
    """
    wait_click_image('app_img/Open_Vault/2_1.png', threshold=0.7, scale=scale)
    wait_image('app_img/Open_Vault/2_2.png', threshold=0.7, scale=scale)
    if (if_exist_click_image('app_img/Open_Vault/3.png', threshold=0.7, scale=scale)):
        wait_many_image(image_paths=['app_img/public_img/get_reward.png', 'app_img/Open_Vault/4_2.png'], threshold=0.7, scale=scale)
        if_exist_click_image('app_img/public_img/get_reward.png', threshold=0.7, scale=scale)

# region 每日签到
def signin_work(scale):
    """
    每日签到过程
    """
    wait_click_image('app_img/sign_in/2.png', threshold=0.7, scale=scale)
    if_exist_click_image('app_img/sign_in/3.png', threshold=0.7, scale=scale)
    time.sleep(0.5)

# region 联盟捐献
def donate_work(donate_count,scale):
    """
    联盟捐献过程
    """
    wait_click_image('app_img/donate/2.png', threshold=0.7, scale=scale)
    wait_many_image(['app_img/donate/2_1.png', 'app_img/donate/3.png'], threshold=0.7, scale=scale)
    if is_image_now('app_img/donate/2_1.png', threshold=0.7, scale=scale):
        back_to_main(scale=scale)
        return 
    wait_click_image('app_img/donate/3.png', threshold=0.7, scale=scale)
    wait_click_image('app_img/donate/4.png', threshold=0.7, scale=scale)
    wait_many_image(['app_img/donate/5_1.png', 'app_img/donate/5_2.png'], threshold=0.7, scale=scale)
    
    for _ in range(donate_count):
        mouse_moveto(1,1)

        if is_image_now('app_img/donate/5_2.png', threshold=0.7, scale=scale):
            break
        click_image('app_img/donate/5_1.png', threshold=0.7, scale=scale)
